home *** CD-ROM | disk | FTP | other *** search
- /* AOMSetButtonText.c */
- /*
- * AddressOMatic Sample
- * AOMSetButtonText.c
- * Copyright © 1993 Apple Computer Inc. All rights reserved.
- */
- #include "AddressOMaticPrivate.h"
-
- /*
- * This is called whenever the button state changes. See AddressOMatic.h
- * for a description of the button text strings how they are computed.
- */
- void
- _AOMSetButtonText(
- register AddressOMaticPtr aomPtr
- )
- {
- short toStringIndex;
- short ccStringIndex;
- OSErr status;
- SDPSelectionState selectionState;
- SDPFindPanelState findState;
- SDPPanelHandle thePanel;
- Boolean enableToButton;
- Boolean enableCCButton;
- AOMSaveState saveState;
- Str255 title;
-
- _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
- enableToButton = FALSE;
- enableCCButton = FALSE;
- if (AOM.toButton != NULL || AOM.ccButton != NULL) {
- /*
- * If we don't know any better, set the "to"
- * button to its current value, and set the
- * "cc" button to either "cc" or "bcc" depending
- * on the state of the option key.
- */
- toStringIndex = AOM.toButtonString;
- ccStringIndex =
- (AOM.optKeyDown == 0)
- ? kAOMCCButtonString
- : kAOMOptCCButtonString;
- switch (AOM.currentMode) {
- case kAOMEnablePDBit:
- thePanel = AOM.pdPanel;
- goto setPanel;
- case kAOMEnablePanelBit:
- thePanel = AOM.browsePanel;
- setPanel: /*
- * The browse panel lets the user examine catalogs and select
- * records. Also, records and containers may be saved into
- * the user's personal directory.
- */
- status = SDPGetPanelSelectionState(thePanel, &selectionState);
- if (status == noErr) {
- switch (selectionState) {
- default:
- case kSDPNothingSelected:
- /*
- * If nothing is selected, leave the button
- * texts alone, but disable both buttons.
- */
- break;
- case kSDPLockedContainerSelected:
- /*
- * A locked container is visible, but cannot
- * be opened. Set the "to" button string
- * to "Open" but leave it disabled. The "cc"
- * button is likewise disabled.
- */
- toStringIndex = kAOMOpenButtonString;
- break;
- case kSDPContainerAliasSelected:
- case kSDPContainerSelected:
- /*
- * This is a normal container. Set the
- * "to" button to open/save, but leave the
- * "cc" button disabled.
- */
- enableToButton = TRUE;
- toStringIndex =
- (AOM.optKeyDown == 0)
- ? kAOMOpenButtonString
- : kAOMSaveButtonString;
- break;
- case kSDPRecordSelected:
- case kSDPRecordAliasSelected:
- /*
- * This is a normal selection. The "to"
- * button should read "To" or "Save"
- */
- enableToButton = TRUE;
- enableCCButton = TRUE;
- toStringIndex =
- (AOM.optKeyDown == 0)
- ? kAOMToButtonString
- : kAOMSaveButtonString;
- break;
- }
- }
- break;
- case kAOMEnableFindBit:
- /*
- * The find panel has three states:
- * -- enter find criterion
- * -- finding
- * -- found data, allowselection
- */
- status = SDPGetFindPanelState(AOM.findPanel, &findState);
- LOG(status, "\pSDPGetFindPanelState");
- if (status == noErr) {
- if ((findState & kSDPItemIsSelectedMask) != 0) {
- /*
- * The user has selected an item. If we are
- * currently searching, set the "to" button to
- * "stop", otherwise set it to "to" or "save"
- * depending on the state of the option key.
- * Since we have a selection, enable the cc button.
- */
- enableToButton = TRUE;
- enableCCButton = TRUE;
- toStringIndex =
- (FINDING)
- ? kAOMStopButtonString
- : (AOM.optKeyDown == 0)
- ? kAOMToButtonString
- : kAOMSaveButtonString;
- }
- else if ((findState & kSDPFindTextExistsMask) != 0) {
- /*
- * Nothing has been selected, but the user has
- * specified a search string. If we are
- * currently searching, set the "to" button
- * to "stop", else, set it to "Find"
- */
- enableToButton = TRUE;
- toStringIndex =
- (FINDING)
- ? kAOMStopButtonString
- : kAOMFindButtonString;
- }
- else {
- /*
- * Nothing has been setup yet. Set the
- * "to" string to "Find" and leave it
- * disabled.
- */
- toStringIndex = kAOMFindButtonString;
- }
- }
- break;
- #ifdef ENABLE_TYPEIN
- case kAOMEnableTypeInBit:
- if ((**AOM.typeInAddress).teLength > 0) {
- /*
- * The user has typed something. The "to"
- * button should read "To" or "Save"
- */
- enableToButton = TRUE;
- enableCCButton = TRUE;
- toStringIndex =
- (AOM.optKeyDown == 0)
- ? kAOMToButtonString
- : kAOMSaveButtonString;
- }
- break;
- #endif
- }
- /*
- * The SDP stuff trashed the font info.
- */
- _AOMSetFont(aomPtr, kAOMLabelFontStyle);
- if (AOM.toButton != NULL) {
- if (toStringIndex != AOM.toButtonString) {
- AOM.toButtonString = toStringIndex;
- GetIndString(title, AOM.stringsResID, toStringIndex);
- SetCTitle(AOM.toButton, title);
- }
- if (enableToButton != AOM.enableToButton) {
- AOM.enableToButton = enableToButton;
- HiliteControl(
- AOM.toButton,
- (enableToButton) ? kActiveControl : kInactiveControl
- );
- _AOMDrawDefaultButtonOutline(AOM.toButton, AOM.isTarget);
- }
- }
- if (AOM.ccButton != NULL) {
- if (ccStringIndex != AOM.ccButtonString) {
- AOM.ccButtonString = ccStringIndex;
- GetIndString(title, AOM.stringsResID, ccStringIndex);
- SetCTitle(AOM.ccButton, title);
- }
- if (enableCCButton != AOM.enableCCButton) {
- AOM.enableCCButton = enableCCButton;
- HiliteControl(
- AOM.ccButton,
- (enableCCButton) ? kActiveControl : kInactiveControl
- );
- }
- }
- }
- AOM.enableToButton = enableToButton;
- AOM.buttonUpdateNeeded = FALSE;
- _AOMRestoreState(&saveState);
- }
-
-